package com.yrh.entry;

import com.yrh.bean.Commodity;
import com.yrh.dao.CommodityDao;
import com.yrh.dao.impl.CommodityImpl;
import org.junit.Test;

import java.util.List;

public class Home {
    CommodityDao dao=new CommodityImpl();
    @Test
    //添加
    public void testAdd(){
        Commodity commodity=new Commodity("百香果",20.0);
        int i = dao.addCom(commodity);
        if (i>0){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    //删除
    @Test
    public void  testDelete(){
        String cname="百香果";
        int i = dao.deleteCom(cname);
        if (i>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
    //修改
    @Test
    public void testUpdate(){
        Commodity commodity=new Commodity("白云边",800.0);
        int i = dao.updateCom(commodity);
        if (i>0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }
    //查询单价
@Test
    public void testPrice(){
        String cname="白云边";
    Commodity commodity = dao.selectByPrice(cname);
    if (commodity!=null){
        System.out.println(cname+"价格是："+commodity.getCprice());
    }else {
        System.out.println("没有该商品");
    }
}
//查询所有数据
    @Test
    public void testAll(){
        List<Commodity> list = dao.selectAll();
        if (list.size()>0) {
            System.out.println("商品信息如下");
            for (Commodity commodity : list) {
                System.out.println(commodity);
            }
        }else {
            System.out.println("没有商品");
        }
    }
}
